<style>
#div_group_tb {
	border-radius: 3px;
	-moz-border-radius: 3px;
	
	box-shadow: 0 3px 3px#C8C8C8;
	-webkit-box-shadow: 0 3px 3px #C8C8C8;
	-moz-box-shadow: 0 3px 3px #C8C8C8;
	
	#float: left;
	#margin-top: -5px;
	#margin-left: -7px;
}

</style>

<script type="text/javascript">
$(document).ready(function(){ 

	$('#tb_group').jqGrid({
		url:'/user/group/?type=json',
		datatype: 'json',
		mtype: 'GET',
		colNames:['组名', '全称', '联系人', '联系电话', '包含的用户',
					'备注'],
		colModel :[ 
		  {name:'name', index:'name', width:40, align:'left'},
		  {name:'fullname', index:'fullname', width:40, align:'left'},
		  {name:'contact_persion', index:'contact_persion', width:40, align:'left'},
		  {name:'telephone', index:'telephone', width:40, align:'left'},
		  {name:'users', index:'users', width:40, align:'left'},
		  {name:'info', index:'info', width:40, align:'left'}
		],
		pager: '#div_group_pager',
		rowNum:10,
		rowList:[10,20,30],
		sortname: 'name',
		sortorder: 'desc',
		viewrecords: true,
		caption: '组列表',
		multiselect: true,
		//shrinkToFit:false,
		width: 800,
		height: 450,
	})

	$('#tb_group').navGrid("#div_group_pager",{add:false, edit:false, del:false, search:false});

	$('#tb_group').navButtonAdd('#div_group_pager', {
	caption: '添加组',
	position: 'last',
	title: '添加一个新组',
	onClickButton: function(){
		$('#div_group_add').load('/user/group_add');
	}
});


$('#tb_group').navButtonAdd('#div_group_pager', {
	caption: '编辑组信息',
	position: 'last',
	title: '编辑组信息',
	onClickButton: function(){
		var selectedids = $('#tb_group').jqGrid('getGridParam', 'selarrrow');
		//alert(selectedids);
		var argv = new Array();
		for (i in selectedids)
		{	
			var selectedid = selectedids[i];
			var isnot_in = true;
			//alert(selectedid);
			for (j=0;j<argv.length;j++)
			{
				if (argv[j] == selectedid){
					isnot_in = false;	
				}
			}
			if (isnot_in) {
				argv.push(selectedid);
			}
		}
		alert(argv);
		if (argv.length!=1){
			alert('请先选中一个组再点击编辑');
			return false;
		}
		$('#div_group_edit').load('/user/group_edit?id='+argv[0]);
	}
});


$('#tb_group').navButtonAdd('#div_group_pager', {
	caption: '删除',
	position: 'last',
	title: '删除选中的组',
	onClickButton: function(){
		if (confirm('确定删除所选内容?')){
		}
		else{
			return false;
		}
		var selectedids = $('#tb_group').jqGrid('getGridParam', 'selarrrow');
		//alert(selectedids);
		var argv = new Array();
		for (i in selectedids)
		{	
			var selectedid = selectedids[i];
			var isnot_in = true;
			//alert(selectedid);
			for (j=0;j<argv.length;j++)
			{
				if (argv[j] == selectedid){
					isnot_in = false;	
				}
			}
			if (isnot_in) {
				argv.push(selectedid);
			}
		}
		//alert(argv);

		if (argv.length>0){}
		else {return false;}
		alert('abc');
		$.ajax({
			type: "DELETE",
			url: "/user/group/?argv="+argv.join('-')
		}).done(function(msg) {
         $('#tb_group').trigger("reloadGrid");
				 alert("Data Saved: "+msg);
		});
	},
});

$(window).bind('resize', function() {
$('#tb_group').setGridWidth($(window).width()*0.705);
	}).trigger('resize');
}); 
</script>

<div id="div_group_tb"> 
<table id="tb_group"></table>
<div id="div_group_pager"></div>
</div>

<div id="div_group_add"></div>
<div id="div_group_edit"></div>
